/**
 * 设置界面
 */

import DialogBase from "./DialogBase";
import SoundManager from "./SoundManager";


const {ccclass, property} = cc._decorator;

@ccclass
export default class SettingDialog extends DialogBase {
    protected show(): void {
        // this.getChild("sp").getComponent(cc.Sprite).fillRange =
        let musicSlider =  this.getChild("slideMusic").getComponent(cc.Slider);
        let audioSlider =  this.getChild("slideAudio").getComponent(cc.Slider);

        musicSlider.node.on('slide', this.onMusicSlideCb, this);
        audioSlider.node.on('slide', this.onAudioSlideCb, this);

        // 初始化音量进度条
        
        let musicVolume = SoundManager.getInstance().getMusicVolume();
        let audioVolume = SoundManager.getInstance().getAudioVolume();

        musicSlider.progress = musicVolume;
        audioSlider.progress = audioVolume;

        this.onMusicSlideCb(musicSlider);
        this.onAudioSlideCb(audioSlider);
    }

    protected onMusicSlideCb(slider: cc.Slider) {
        this.getChild("music_progress").getComponent(cc.Sprite).fillRange = slider.progress;
        SoundManager.getInstance().setMusicVolume(Math.floor(slider.progress * 100) / 100)
        console.log("music slider", slider.progress);
    }
    
    protected onAudioSlideCb(slider) {
        this.getChild("audio_progress").getComponent(cc.Sprite).fillRange = slider.progress;
        SoundManager.getInstance().setAudioVolume(Math.floor(slider.progress * 100) / 100)
        console.log("audio slider", slider.progress);
    }

    protected closeDialogClickCb(): void {
        this.node.active = false;
    }
}
